 function varlr=varksm(x,m); 
% ====================================================
% function VARLR=varksm(x,m); 
% Long-run variance using Kernel Smoothing of order m 
% If m not provided then default value of 
% M = 30 is used 
% AJ (c) December 29 2006 
% ====================================================
t=length(x); 
if nargin==1 | isempty(m); 
     m=30;
end
xdev=x-mean(x)*ones(t,1); 
covec=zeros(m,1); w=zeros(m,1); 
for ii=1:m; 
     w(ii)=1-(ii/(m+1)); 
     covec(ii)=((xdev(ii+1:end)')*xdev(1:end-ii))/t; 
end  
varlr=(var(x)+2*sum((w.*covec)))/t; 